var t = getApp(), e = t.requirejs("core"), a = t.requirejs("wxParse/wxParse"), i = t.requirejs("biz/diypage"), s = t.requirejs("jquery");
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		id: '',
		list: [],
		page: 1,
		pagesize: 10,
		total: 0,
		curr: 0,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		console.log(options.id)
		const _this = this
		if (options.id) {
			_this.setData({
				id: options.id
			})
			_this.getDetail()
		}
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		this.setData({
			page:1,
			list:[]
		})
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function (e) {
		console.log(e)
		let data = this.data.list.filter(item => {
			return item.id == e.target.dataset.id

		})
		console.log(data)
		return {
			title: data[0].goods_title,
			imageUrl: data[0].thumb,
			path: `/pages/Videolist/index?id=${e.target.dataset.id}`
		}
		
	},
	//跳转到记录
	go() {
		console.log('go')
		wx.navigateTo({
			url: '/pages/Myvideo/index'
		})
	},
	//跳转到记录
	add() {
		wx.navigateTo({
			url: '/pages/Releasevideo/index'
		})
	},
	tianjia: function () {
		console.log('11111111111111')
	},
	//获取视频详情
	getDetail() {
		const _this = this
		e.get("member/shipin/voide_info", {
			id: _this.data.id
		}, function (t) {
			console.log('获取详情-------------', t)
			_this.setData({
				list: _this.data.list.concat(t.voide_info)
			})
			_this.getList()
		});
	},
	//切换
	changeList(e) {
		const _this = this
		const videoContext = wx.createVideoContext('myVideo')
		videoContext.stop()
		if (e.detail.current > _this.data.curr && e.detail.current == _this.data.list.length - 3) {
			if (_this.data.total > _this.data.list.length) {
				_this.setData({
					page: _this.data.page + 1
				})
				_this.getList()
			}
		}
	},
	//获取视频列表
	getList() {
		const _this = this
		e.get("member/shipin/voide_list", {
			page: _this.data.page,
			pagesize: _this.data.pagesize
		}, function (t) {
			_this.setData({
				total: t.total
			})
			if (t.list) {
				let data = t.list.filter(item => {
					return item.id != _this.data.id
				})
				_this.setData({
					list: _this.data.list.concat(data)
				})
			}

		});
	},
	//点赞
	likeClick(data) {
		const _this = this
		let is_zan = `list[${data.currentTarget.dataset.index}].is_zan`
		let zannum = `list[${data.currentTarget.dataset.index}].zannum`
		e.get("member/shipin/voide_zan", {
			type: data.currentTarget.dataset.type,
			id: data.currentTarget.dataset.id
		}, function (t) {
			if (t.error == 0) {
				if (data.currentTarget.dataset.type == 'up') {
					_this.setData({
						[is_zan]: 1,
						[zannum]: Number(_this.data.list[data.currentTarget.dataset.index].zannum) + 1
					})
				} else {
					_this.setData({
						[is_zan]: 0,
						[zannum]: Number(_this.data.list[data.currentTarget.dataset.index].zannum) - 1
					})
				}
			} else {
				wx.showToast({
					title: t.msg,
					icon: 'none',
					duration: 2000
				})
			}
		});
	},
	//商品详情
	goodDetail(e) {
		wx.navigateTo({
			url: `/pages/goods/detail/index?id=${e.currentTarget.dataset.id}`,

		})
	}
})